<%@page import="com.mavenrentcars.model.Reservation"%>
<%@page import="java.util.Set"%>
<%@page import="com.mavenrentcars.model.Place"%>
<%@page import="java.util.List"%>
<%@page import="com.mavenrentcars.model.Car"%>
<%@page import="java.util.HashMap"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/header.jsp" %>
<% 
	Car item = (Car) request.getAttribute("item");
    Set<Place> places = (Set<Place>) request.getAttribute("places");
    List<Reservation> reservations = (List<Reservation>) request.getAttribute("reservations");
    String json_days = (String) request.getAttribute("json_days");
    Boolean vote = (Boolean) request.getAttribute("vote");
%>
        <h1>Order Info</h1>
        <div>
            <table border="0">
                <tbody>
                    <tr>
                        <td>From: <input type="text" id="order_from_order_form" name="order_from" /></td>
                        <td>To: <input type="text" id="order_to_order_form" name="order_to" /></td>
                    </tr>
                    <tr>
                        <td><div id="order_from_date_picker" /></td>
                        <td><div id="order_to_date_picker" /></td>
                    </tr>
                </tbody>
            </table>
        </div>
                            
        <%
        if (reservations != null) {
            for(Reservation res : reservations) {
        %>
            <div>
                <%= res.getBeginDate() %>  <%= res.getEndDate() %>
                <a href="account_item.htm?id=<%= res.getUser().getId() %>">
                    <%= res.getUser().getUserName() %>
                </a>
            </div>
        <% }
        }%>
        <div>
            Owner: 
            <a href="account_item.htm?id=<%= item.getUser().getId() %>">
                <%= item.getUser().getUserName() %>
            </a>
        </div>
            
        <div>
            Rating: <%= item.getRating() %> 
            <input type="hidden" id="vote_order_form" value="<%= ((!vote) ? "false" : "true") %>" />
        </div>    
        
        <% if (!vote) { %>
            <div>
                Vote please:
                <select id="rating_order_form">
                    <option value=""></option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                </select>

            </div>
        <% } %>
                    
        <div>
            <table border="0">
                <tbody>
                    <tr>
                        <td>Set up Finish Place:</td>
                        <td>
                            <select id="finish_place_order_form">
                            <%
                            for(Place place : places) {
                            %>
                            <option value="<%= place.getId() %>">
                                <%= place.getPlaceName() %>
                            </option>
                            <% } %>
                            </select>
                        </td>
                        <td>
                            <input type="submit" id="send_order_form" value="Send Order" />
                            <input type="hidden" id="order_from_car" value="<%= item.getId() %>" />
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
                    
        <div>
        <table border="0">
            <tbody>
                <tr>
                    <td>
                        <div >
                        <table border="0">
                            <tbody>
                                <tr>
                                    <td>Model:</td>
                                    <td><%= item.getModel() %></td>
                                </tr>
                                <tr>
                                    <td>Output Year:</td>
                                    <td><%= item.getOutputYear() %></td>
                                </tr>
                                <tr>
                                    <td>Insurance:</td>
                                    <td><%= item.getInsurance() %></td>
                                </tr>
                                <tr>
                                    <td>Price:</td>
                                    <td><%= item.getPrice() %></td>
                                </tr>
                                <tr>
                                    <td>Start Place:</td>
                                    <td><%= item.getStartPlace().getPlaceName() %></td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    </td>
                    
                    <td style="vertical-align: top;">
                        <div>
                            <table border="0">
                            <tbody>
                                <tr>
                                    <td colspan="2">Places:</td>
                                </tr>
                                <%
                                for(Place place : places) {
                                %>
                                <tr>
                                    <td><%= place.getPlaceName() %></td>
                                </tr>
                                <% } %>
                            </tbody>
                            </table>
                        </div>
                    </td>
               </tr>
            </tbody>
        </table>
    </div>
		
    <script type="text/javascript">
		
		$(document).ready(function(){
            var orderController = new OrderController(<%=json_days%>);
            orderController.init();
		});
	</script>
    
<%@ include file="/WEB-INF/jsp/footer.jsp" %>